package com.it.text;

import com.it.domain.Student;

import java.util.ArrayList;

public class ArrayLIst03 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        ArrayList<Student> newList = new ArrayList<>();
        Student stu = new Student();

        list.add(new Student("张三",22));
        list.add(new Student("李四",14));
        list.add(new Student("王五",15));

        newList = flict(list);

        for (int i = 0; i < newList.size(); i++) {
            stu = newList.get(i);
            System.out.println(stu.getName() + "-----" + stu.getAge());
        }

    }

    private static ArrayList<Student> flict(ArrayList<Student> list) {
        ArrayList<Student> newList = new ArrayList<>();

        Student stu = new Student();

        for (int i=0;i<list.size();i++) {
            stu = list.get(i);
            if(stu.getAge() <= 18)
            {
                newList.add(stu);
            }
        }
        return newList;
    }
}
